home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOpus Plus
/
DOpus Plus.iso
/
Tutorial
/
C Guide
/
Time_module
/
modinit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-09-20
|
5KB
|
195 lines
/****************************************************************************
modinit.c - standard initialisation for Opus 5 modules
****************************************************************************/
#ifndef _DOPUS_MODULE_DEF
#define _DOPUS_MODULE_DEF
#include <dopus/modules.h>
#endif
#ifndef CLIB_EXEC_PROTOS_H
#include <clib/exec_protos.h>
#include <pragmas/exec_pragmas.h>
#endif
#ifndef EXEC_MEMORY_H
#include <exec/memory.h>
#endif
#ifndef CLIB_LOCALE_PROTOS_H
#include <clib/locale_protos.h>
#include <pragmas/locale_pragmas.h>
#endif
/********************************************************************/
// SAS/C stuff
int __saveds __UserLibInit(void);
void __saveds __UserLibCleanup(void);
struct Library *DOSBase;
struct Library *AslBase;
struct Library *GfxBase;
struct Library *DOpusBase;
struct Library *LocaleBase;
struct Library *UtilityBase;
struct Library *DiskfontBase;
struct Library *GadToolsBase;
struct Library *IntuitionBase;
#ifdef DATATYPES
struct Library *DataTypesBase;
#endif
#ifdef AREXX
struct Library *RexxSysBase;
#endif
APTR mempool;
// Locale pointer
struct DOpusLocale *locale;
// Library initialisation code
__saveds __UserLibInit()
{
// Initialise pointers
AslBase = 0;
GfxBase = 0;
DOpusBase=0;
LocaleBase=0;
UtilityBase=0;
DiskfontBase = 0;
GadToolsBase = 0;
IntuitionBase = 0;
#ifdef DATATYPES
DataTypesBase = 0;
#endif
#ifdef AREXX
RexxSysBase=0;
#endif
locale=0;
mempool = NULL;
// Get DOS library (can't really fail)
DOSBase=OpenLibrary("dos.library",0);
// Open other libraries we need
if( !(AslBase = OpenLibrary("asl.library", 37)) ||
!(GfxBase=OpenLibrary("graphics.library",37)) ||
!(DOpusBase=OpenLibrary("dopus5.library",55)) ||
!(UtilityBase=OpenLibrary("utility.library",37)) ||
!(DiskfontBase=OpenLibrary("diskfont.library",37)) ||
!(GadToolsBase = OpenLibrary( "gadtools.library", 37)) ||
!(IntuitionBase = OpenLibrary( "intuition.library", 37)) ||
#ifdef DATATYPES
!(DataTypesBase = OpenLibrary( "datatypes.library", 39)) ||
#endif
#ifdef AREXX
!(RexxSysBase=OpenLibrary("rexxsyslib.library",0)) ||
#endif
NULL
)
return 1;
if( !(mempool = NewMemHandle(4096, 3072, MEMF_CLEAR|MEMF_PUBLIC)) ||
!(locale = AllocMemH(mempool, sizeof(struct DOpusLocale))) )
{
return 1;
}
init_locale_data(locale);
// Open locale library
if (LocaleBase=OpenLibrary("locale.library",38))
{
// Store library pointer
locale->li_LocaleBase=LocaleBase;
// Open catalog if name supplied
if (module_info.locale_name)
{
struct TagItem tags[2];
// If MODULEF_CATALOG_VERSION is set, we do version checking
tags[0].ti_Tag=(module_info.flags&MODULEF_CATALOG_VERSION)?OC_Version:TAG_IGNORE;
tags[0].ti_Data=module_info.ver;
tags[1].ti_Tag=TAG_END;
// Open catalog
locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,tags);
}
// Get default lolale
locale->li_Locale=OpenLocale(0);
}
return NULL; // Succeeded
}
// Clean up
void __saveds __UserLibCleanup()
{
if( mempool )
{
if( locale )
{
if( LocaleBase )
{
CloseLocale(locale->li_Locale);
CloseCatalog(locale->li_Catalog);
CloseLibrary(LocaleBase);
}
FreeMemH(locale);
}
FreeMemHandle( mempool );
}
// Close libraries
CloseLibrary( AslBase );
CloseLibrary( GfxBase );
CloseLibrary( DOpusBase );
CloseLibrary( DiskfontBase );
CloseLibrary( UtilityBase );
#ifdef DATATYPES
CloseLibrary( DataTypesBase );
#endif
#ifdef AREXX
CloseLibrary( RexxSysBase );
#endif
CloseLibrary( GadToolsBase );
CloseLibrary( IntuitionBase );
CloseLibrary( DOSBase );
}
// This routine is called by Opus to find out what the module does
ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
{
// Return module information
if (num==-1) return &module_info;
// Valid function number?
if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
// Return function description
return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
}
/********************************************************************/